﻿using System.Data;
using Navigant.Infrastructure.Cases;
using Navigant.Infrastructure.EntityFactoryFramework;
using Navigant.Infrastructure.Helpers;
using Navigant.Model.PreservationNotices;
using Navigant.Infrastructure.DomainBase;

namespace Navigant.Infrastructure.Repositories
{
    public class PreservationNoticeFactory : IEntityFactory<PreservationNotice>
    {
        #region IEntityFactory<PreservationNotice> Members

        public PreservationNotice BuildEntity(IDataReader reader, ICase parentCase)
        {
            return new PreservationNotice(DataHelper.GetInteger(reader["PreservationNoticeHistoryID"]),
                parentCase, 
                DataHelper.GetInteger(reader["CustodianID"]), 
                DataHelper.GetString(reader["FromAddress"]),
                DataHelper.GetString(reader["MessageSubject"]), 
                DataHelper.GetString(reader["MessageBody"]),
                DataHelper.GetString(reader["Identifier"]),
                DataHelper.GetInteger(reader["PreservationNoticeID"]),
                DataHelper.GetString(reader["PreservationNoticeName"]),
                DataHelper.GetEnumValue<PreservationNoticeStatus>(reader["EventType"]),
                DataHelper.GetDateTime(reader["DateEmailMessageCreated"]),
                DataHelper.GetNullableDateTime(reader["DateEmailMessageSent"]),
                DataHelper.GetNullableDateTime(reader["DateAcknowledged"]),
                DataHelper.GetInteger(reader["VerificationTries"]));
        }

        public void LoadExtendedProperties(IDataReader reader, PreservationNotice entity)
        {
        }

        #endregion

        internal static SmtpLogEntry BuildLogEntry(IDataReader reader)
        {
            return new SmtpLogEntry(DataHelper.GetInteger(reader["InetLogID"]),
                DataHelper.GetDateTime(reader["TimeStamp"]), DataHelper.GetString(reader["MailTo"]));
        }

        internal static Attachment BuildAttachment(IDataReader reader)
        {
            return new Attachment(DataHelper.GetByteArrayValue(reader["Attachment"]), 
                "Attachment", string.Empty);
        }
    }
}